#ifndef _MW_MESSAGE_BUFFER_H
#define _MW_MESSAGE_BUFFER_H


/*
  Meanwhile - Unofficial Lotus Sametime client library
  
  Copyright (c) 2007 Christopher O'Brien <siege@preoccupied.net>
  
  License: LGPL
  
  This library is free software; you can redistribute it and/or modify
  it under the terms of version 2 the GNU Library General Public
  License as published by the Free Software Foundation.
                                                                                
  This library is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA
*/


/** @file mw-message-buffer.h
    @since 2.0.0

    Utility structure and functions for buffering complete messages
*/


#include <glib.h>


G_BEGIN_DECLS


typedef struct mw_message_buffer MwMessageBuffer;


typedef void (*MwMessageBufferCallback)(MwMessageBuffer *msgbuf,
					const guchar *data, gsize len,
					gpointer user_data);


MwMessageBuffer *mw_message_buffer_new(MwMessageBufferCallback callback,
				       gpointer user_data,
				       GDestroyNotify user_data_free);


/** Feed data to a message buffer. If the data completes a full
    message, trigger the mw_message_buffer_cb specified at
    creation. If an incomplete message remains after processing data,
    it will be buffered awaiting more data for completion. */
void mw_message_buffer_feed(MwMessageBuffer *msgbuf,
			    const guchar *data, gsize len);


/** clear any incomplete messages from the buffer */
void mw_message_buffer_reset(MwMessagebuffer *msgbuf);


/** reset and free the message buffer. If a GDestroyNotify function
    was specified at creation, it will be called on user_data. */
void mw_message_buffer_free(MwMessageBuffer *msgbuf);


G_END_DECLS


#endif /* _MW_MESSAGE_BUFFER_H */
